<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
</head>

<body>
    <button id="btn">点击</button>
    <script>
        const oBtn = document.getElementById('btn');
        /* oBtn.onclick = function () {
            // $.getJSON("https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd=前端&cb=?", function (data) {
            //     console.log(data);
            // })
        } */



        function fn1(data) {
            console.log(data);
        }
        let newScript = null;
        oBtn.onclick = function () {
            if (newScript) {
                newScript.remove();
            }
            //创建一个script标签
            newScript = document.createElement("script");
            //给script标签一个src 这个src就是我们跨域请求的地址
            newScript.src = "https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd=1&cb=fn1";
            //把script标签插入到html中，就会自动发送请求
            document.body.appendChild(newScript);
        }
    </script>
</body>

</html>